#include "mesh/GeneratedMesh.h"

#include <gtest/gtest.h>
#include <iostream>
#include <vector>
using std::vector;

TEST(GeneratedMesh, BuildFaceSet3D)
{
    auto param = GeneratedMesh::validParams();  //add

    Id3 dim = { 2,1,1 };
    param.set<Id3>("dims", dim);

    GeneratedMesh mesh(param);
    mesh.Build();

    EXPECT_EQ(mesh.GetFaceSet().GetNumberOfCells(), 11);

    mesh.WriteCellSet("face_set3.vtk", mesh.GetFaceSet());
}

TEST(GeneratedMesh, 3D)
{
    auto param = GeneratedMesh::validParams();  //add

    Id3 dim = { 10,10,10 };
    param.set<Id3>("dims", dim);

    GeneratedMesh mesh(param);

    mesh.Build();
    EXPECT_EQ(mesh.GetNumberOfPoints(), (dim[0]+1)*(dim[1]+1)*(dim[2]+1));
    EXPECT_EQ(mesh.GetNumberOfCells(), dim[0] * dim[1] * dim[2]);

    mesh.WriteCellSet("cell_set3.vtk", mesh.GetCellSet());
    mesh.WriteCellSet("boundary_set3.vtk", mesh.GetBoundarySet());
}

TEST(GeneratedMesh, 2D)
{
    auto param = GeneratedMesh::validParams();  

    Id3 dim = { 10,10,0 };
    param.set<Id3>("dims", dim);

    GeneratedMesh mesh(param);

    mesh.Build();
    EXPECT_EQ(mesh.GetNumberOfPoints(), (dim[0] + 1) * (dim[1] + 1) * (dim[2] + 1));
    EXPECT_EQ(mesh.GetNumberOfCells(), dim[0] * dim[1]);

    mesh.WriteCellSet("cell_set2.vtk", mesh.GetCellSet());
    mesh.WriteCellSet("boundary_set2.vtk", mesh.GetBoundarySet());
}

TEST(GeneratedMesh, 1D)
{
    auto param = GeneratedMesh::validParams();

    Id3 dim = { 10,0,0 };
    param.set<Id3>("dims", dim);

    GeneratedMesh mesh(param);

    mesh.Build();
    EXPECT_EQ(mesh.GetNumberOfPoints(), (dim[0] + 1) * (dim[1] + 1) * (dim[2] + 1));
    EXPECT_EQ(mesh.GetNumberOfCells(), dim[0]);

    mesh.WriteCellSet("cell_set1.vtk", mesh.GetCellSet());
    mesh.WriteCellSet("boundary_set1.vtk", mesh.GetBoundarySet());
}



TEST(GeneratedMesh, BuildFaceSet2D)
{
    GeneratedMesh mesh(Id3{10,10,0});
    mesh.Build();
    //mesh.BuildFaceSet();

    EXPECT_EQ(mesh.GetFaceSet().GetNumberOfCells(), 220);

    mesh.WriteCellSet("face_set2.vtk", mesh.GetFaceSet());
}

TEST(GeneratedMesh, BuildFaceSet1D)
{
    GeneratedMesh mesh(Id3{ 10,0,0 });
    mesh.Build();

    EXPECT_EQ(mesh.GetFaceSet().GetNumberOfCells(), 11);

    mesh.WriteCellSet("face_set1.vtk", mesh.GetFaceSet());
}